<template>
	<view class="content">
		<scroll-view class="article-select-view" scroll-x="true">
			<view class="f-row r-center">
				<view :class="tabid==index?'article-view on':'article-view'" v-for="(item, index) in articleTypeAry"
					:key="index" @click="getArticleList(item.dictCode,index)">{{item.dictLabel}}</view>
			</view>
		</scroll-view>
		<view class="wxad" v-if="bannerAd">
			<ad unit-id="adunit-32ee9f1ef2bea9fa" @error="offAd" @close="offAd"></ad>
		</view>
		<view class="article-view f-col r-center">
			<view class="article-item" v-for="(item, index) in articleAry" :key="index" @click="onClickArticle(item)">
				<image class="article-icon" :src="item.coverUrl"></image>
				<text class="article-title-text">{{item.title}}</text>
				<view class="article-auther-icon">
					<image :src="item.authorImage"></image>
				</view>
				<text class="article-auther">{{item.author}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bannerAd: true,
				articleTypeAry: [],
				articleAry: [],
				tabid: 0,
			};
		},
		components: {

		},
		onLoad(item) {
			let that = this;
			this.$api.request({
				url: this.$api.imageType,
				data: {
					type: "articletype"
				}
			}).then(resp => {
				console.log(resp, '1111');
				if (resp.code == 200) {
					that.articleTypeAry = resp.data;

					if (resp.data) {
						that.getArticleList(resp.data[0].dictCode);
					}
				}
			});
		},

		methods: {
			offAd() {
				this.bannerAd = false
			},
			onClickArticle(item) {
				uni.navigateTo({
					url: "/pages/index/articleWeb?articleid=" + item.id
				})
			},
			getArticleList(categoryId, index) {
				this.tabid = index
				let that = this;
				this.$api.request({
					url: this.$api.articlesList,
					method: "POST",
					data: {
						"categoryId": categoryId
					}
				}).then(resp => {
					console.log(resp);
					if (resp.code == 200) {
						that.articleAry = resp.data;
					}
				});
			}
		},
	};
</script>

<style lang="less" scoped>
	@import "@/static/css/app.less";

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;

		.article-select-view {
			position: relative;
			margin-top: 20rpx;
			width: 710rpx;

			.article-view {
				position: relative;
				width: 200rpx;
				height: 80rpx;
				line-height: 80rpx;
				border-radius: 10rpx;
				background: #FFFFFF;
				text-align: center;
				margin-left: 5rpx;
				margin-right: 5rpx;
				font-size: 28rpx;
			}

			.article-view.on {
				background-color: red;
				color: #fff;
			}
		}

		.wxad {
			position: relative;
			margin-top: 20rpx;
			width: 710rpx;
			border-radius: 10rpx;
			overflow: hidden;
		}

		.article-view {
			position: relative;
			width: 710rpx;
			overflow: hidden;
			background: #fff;
			border-radius: 10rpx;
			margin-top: 20rpx;

			.article-item {
				position: relative;
				width: 100%;
				height: 210rpx;
				border-bottom: 1prx solid #666666;

				.article-icon {
					position: absolute;
					width: 160rpx;
					height: 160rpx;
					top: 25rpx;
					left: 30rpx;
					border-radius: 10rpx;
				}

				.article-title-text {
					position: absolute;
					font-size: 30rpx;
					font-weight: 600;
					top: 20rpx;
					left: 210rpx;
					right: 30rpx;
					height: 80rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					display: -webkit-box;
					color: #333333;
				}

				.article-auther-icon {
					position: absolute;
					bottom: 30rpx;
					left: 210rpx;
					width: 36rpx;
					height: 36rpx;
					border-radius: 36rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.article-auther {
					position: absolute;
					bottom: 32rpx;
					left: 260rpx;
					font-size: 24rpx;
					color: #666666;
				}
			}

			.article-item:last-child {
				border-bottom: none;
			}
		}
	}
</style>